<template>
	<view>
		<!-- 班级列表为空时 -->
		<view v-show="classItems.length === 0 " class="classNone">
			<image src="../../static/空白页面插图.png" mode=""></image>
			<view class="goIn" @click="leadClass">暂无班级</view>
		</view>
		<!-- 班级列表 -->
		<view v-show="classItems.length > 0" class="card" v-for="item in classItems" :id="item.id"
			@click="goClassDtail">
			<uni-card :title="item.cname + '班'" :extra="item.count + '人'">
				<text class="uni-body"> 班级信息: {{item.create_time}} </text>
			</uni-card>
		</view>

	</view>
</template>

<script>
	import server from "@/util/http.js"
	export default {
		data() {
			return {
				classItems: [],
				userInfo: {},
			}
		},
		methods: {
			//班级详情
			goClassDtail(e) {
				uni.navigateTo({
					url: `../classDetail/classDetail?id=${e.currentTarget.id}`
				})
			}
		},
		//页面显示 时调用接口 显示班级信息 班级名 课程 学生人数 
		onShow() {},
		onLoad(option) {
			uni.getStorage({
				key: 'user',
				success: (res) => {
					console.log(res.data);
					this.userInfo = res.data;
				}
			});
			//页面初次加载
			if (JSON.stringify(option) !== "{}" && JSON.stringify(this.userInfo) === "{}") {
				server({
					url: 'http://127.0.0.1:4523/mock/906666/classitem',
					method: 'get',
					success: res => {
						this.classItems = res.data;
						uni.showToast({
							title: '导课成功'
						})
						uni.setStorage({
							key: 'user',
							data: option,
							success() {
								console.log('cg');
							}
						})
					},
					fail: e => {
						console.log(e);
					}
				})
			} else {
				console.log(JSON.stringify(this.userInfo) === "{}");
				console.log(JSON.stringify(option) !== "{}");
				console.log(this.userInfo.id);
				console.log(this.userInfo.name);
			}
		}
	}
</script>

<style scoped>
	.classNone {
		text-align: center;
		margin-top: 300rpx;
	}

	.classNone image {
		width: 200rpx;
		height: 200rpx;
	}

	.goIn {
		margin-top: 20rpx;
		font-size: 34rpx;
		font-weight: 500;
		font-family: 'Courier New', Courier, monospace;
	}

	>>>.uni-nav-bar-text {
		font-size: 32rpx;
		font-weight: 600;
	}
</style>
